import axios from 'axios'
import {
    Dialog
} from 'vant';
let requestOk = false,
    // host = "http://crmtest.jzsoft.cn",
    host = "..";
try {
    let localUrl = "http://localhost:8080,http://192.168.8.88:8080,http://192.168.8.88:8081,";
    if (
        window.location.origin &&
        localUrl.indexOf(window.location.origin) != -1
    ) {
        host = "/api"
    } else {
        host = "http://testapi.link.jzsoft.cn"
    }
} catch (error) {
    console.log(error)
}

function jzalert(v, t, k) {
    Dialog.alert({
        title: (t == null ? "提示" : t),
        message: v,
        confirmButtonText: (k == null ? "确定" : k)
    }).then(() => {
        // on close
    });
}

function jzloading(m) {
    if (typeof dd != "undefined" && dd && dd.env && dd.env.platform == "notInDingTalk") {
        return;
    }
    dd.device.notification.showPreloader({
        text: (m == null ? '加载中...' : m), //loading显示的字符，空表示不显示文字
        showIcon: true, //是否显示icon，默认true
        onSuccess: function(result) {},
        onFail: function(err) {}
    })
}

export function netWork({ mod, callback, apiUrl, postData, vueObj, }) {

    let url = apiUrl;
    let checkUrl = "";
    axios.defaults.withCredentials = true;
    requestOk = false;

    axios({
        url: url.replace(/ /g, ""),
        data: postData,
        method: mod || 'post'
    }).then((res) => {
        requestOk = true;
        let copyData = JSON.parse(JSON.stringify(res.data))
        return callback(copyData)
    }).catch((msg) => {
        requestOk = true;
        console.log("网络请求出错了：" + url, msg);
    })
}